<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>风险处置</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="./../js/index.js"></script>

    <style>
        table {
            word-break: break-all;
            word-wrap: break-word;
            table-layout: auto;
        }
	div{
            font-size: 1rem;
        } 

        td {
            width: 10rem;
        }
    </style>
</head>

<body>

    <div class="container-lg">
        <h3>风险录入</h3>
		
        <div class="form-group">
            <textarea class="form-control" rows="12" id="inputinfo" placeholder="从台账Excel粘贴车牌号、风险类型、风险等级、速度、风险位置、处置类型等字段"></textarea>
        </div>

        
        <br/>
		<h3>风险预警</h3>
        <div class="form-group">
            <textarea class="form-control" onclick="copyText(1)" rows="4" id="riskStr"
                placeholder="风险预警"></textarea><span id="cp1" style="font-size: 40px;color: #f20d0d;">复制成功！</span>
        </div>
		<br/>
        <h3>监控建议</h3>
        <div class="form-group">
            <textarea class="form-control" onclick="copyText(2)" rows="4" id="monitorStr" placeholder="监控建议"></textarea>
        </div>
        <span id="cp2" style="font-size: 40px;color: #f20d0d;">复制成功！</span>
		
		 <br/> <br/> <br/>
		<h3>粘贴示例</h3>
		<div> 
			<img src="../imgs/risk.png">
		</div>
		
		<br/> <br/> <br/>

    </div>


    <script>

       
		var cp1 = document.getElementById("cp1"); //
        cp1.style.display = "none";

        var cp2 = document.getElementById("cp2"); //
        cp2.style.display = "none";


		//风险处置
        function risk() {

            var inputinfo = document.getElementById("inputinfo").value
			
			inputinfo = inputinfo.trim()
			
			document.getElementById("monitorStr").value=''

			document.getElementById("riskStr").value=''
            
			// 数据校验，需要包含一下关键字
			if (inputinfo == null) {

                return false
            }

            if (inputinfo.indexOf('粤') == -1) {
				console.log(1)
				
				return
            } 
			
			if (inputinfo.indexOf('报警') == -1) {
				console.log(2)
				return
            }
			
			if (inputinfo.indexOf('警情') == -1 && inputinfo.indexOf('风险') == -1) {
				console.log(3)
				
				return
            }
			
			if (inputinfo.indexOf('属实') == -1 && inputinfo.indexOf('误报') == -1) {
				console.log(4)
				return
            }

            var strArray = inputinfo.split(/\r\n|\n/)
            console.log(strArray)

			
			var wubaoNum = 0; //设备误报数量
			
			var riskTrueNum = 0; //属实风险数量
			
			var otherRisk = 0; // 其它风险属实数量
			var otherRiskStr = ''; // 其它风险属实数量
			
			var flag = 0; // 属实风险标识
			
			
			var  answerPhone = 0;        // 接打电话数量 
			var  answerPhoneStr = '';        // 接打电话数量 
			var  playPhone = 0;        // 玩手机 
			var  playPhoneStr = '';        // 玩手机 
			var  smoking  = 0; //抽烟
			var  smokingStr  = ''; //抽烟
			var  overspeed  = 0;// 超速
			var  overspeedStr  = '';// 超速
			var  overtime = 0;//超时
			var  overtimeStr = '';//超时
			var  equipmentObstruction = 0 ;// 设备遮挡
			var  equipmentObstructionStr = '' ;// 设备遮挡
			var  safetyBelt = 0;// 安全带
			var  safetyBeltStr = '';// 安全带
			var  bothHands = 0; // 双手脱把
			var  bothHandsStr = ''; // 双手脱把
			var  fatigue = 0;
			var  fatigueStr = ''; // 生理疲劳
			var  communication = 0;
			var  communicationStr = ''; // 通讯失效

            for (var i = 0; i < strArray.length; i++) {

				flag = 0;
				if (strArray[i].trim() != "") {
					var array = strArray[i].split('\t')
					
					var plateNumber = array[0] //车牌号码
					
					if(plateNumber.indexOf('粤') == -1){
						return
					}
					
					if (strArray[i].indexOf('设备误报') !== -1){
						wubaoNum = wubaoNum+1
					}
					else if(strArray[i].indexOf('其他风险') !== -1){
						otherRisk =otherRisk+1
						
						if(otherRiskStr.indexOf(array[0].trim()) == -1){
								otherRiskStr = otherRiskStr+array[0].trim() + ","
							}
						
						
					}
					else {
						riskTrueNum =riskTrueNum+1
						flag = 1;
					}
					
					if(flag ==1){
						if(strArray[i].indexOf('接打手机') != -1){
							answerPhone =answerPhone+1
							
							if(answerPhoneStr.indexOf(array[0].trim()) == -1){
								answerPhoneStr = answerPhoneStr+array[0].trim() + ","
							}
							
						}
						else if(strArray[i].indexOf('玩手机') != -1){
							playPhone =playPhone+1
							if(playPhoneStr.indexOf(array[0].trim()) == -1){
								playPhoneStr = playPhoneStr+array[0].trim() + ","
							}
							
						
						}
						else if(strArray[i].indexOf('抽烟') != -1){
							smoking =smoking+1
							if(smokingStr.indexOf(array[0].trim()) == -1){
								smokingStr = smokingStr+array[0].trim() + ","
							}
							
						
						}
						else if(strArray[i].indexOf('超速') != -1){
							overspeed=overspeed+1
							if(overspeedStr.indexOf(array[0].trim()) == -1){
								overspeedStr = overspeedStr+array[0].trim() + ","
							}
							
							
							
						}
						else if(strArray[i].indexOf('超时') != -1){
							overtime =overtime+1
							if(overtimeStr.indexOf(array[0].trim()) == -1){
								overtimeStr = overtimeStr+array[0].trim() + ","
							}
							
						
						}
						else if(strArray[i].indexOf('设备遮挡') != -1){
							equipmentObstruction =equipmentObstruction+1
							if(equipmentObstructionStr.indexOf(array[0].trim()) == -1){
								equipmentObstructionStr = equipmentObstructionStr+array[0].trim() + ","
							}
							
						
						}
						else if(strArray[i].indexOf('安全带') != -1){
							safetyBelt =safetyBelt+1		
							if(safetyBeltStr.indexOf(array[0].trim()) == -1){
								safetyBeltStr = safetyBeltStr+array[0].trim() + ","
							}
							
						
						}
						else if(strArray[i].indexOf('方向盘') != -1){
							bothHands =bothHands+1
							if(bothHandsStr.indexOf(array[0].trim()) == -1){							
								bothHandsStr = bothHandsStr+array[0].trim() + ","
							}
							
						
						}
						else if(strArray[i].indexOf('疲劳') != -1){
							fatigue =fatigue+1
							if(fatigueStr.indexOf(array[0].trim()) == -1){							
								fatigueStr = fatigueStr+array[0].trim() + ","
							}
							
						
						}
						else if(strArray[i].indexOf('通讯失效') != -1){
							communication =communication+1
							if(communicationStr.indexOf(array[0].trim()) == -1){							
								communicationStr = communicationStr+array[0].trim() + ","
							}
							
						
						}
					}
				
				}
            }
            if(answerPhoneStr !=''){
				answerPhoneStr = answerPhoneStr.substring(0, answerPhoneStr.length - 1);
			}
			
			if(playPhoneStr !=''){
				playPhoneStr = playPhoneStr.substring(0, playPhoneStr.length - 1);
			}
			if(smokingStr !=''){
				smokingStr = smokingStr.substring(0, smokingStr.length - 1);
			}
			
			if(overspeedStr !=''){
				overspeedStr = overspeedStr.substring(0, overspeedStr.length - 1);
			}
			if(overtimeStr !=''){
				overtimeStr = overtimeStr.substring(0, overtimeStr.length - 1);
			}
			
			if(equipmentObstructionStr !=''){
				equipmentObstructionStr = equipmentObstructionStr.substring(0, equipmentObstructionStr.length - 1);
			}
			if(safetyBeltStr !=''){
				safetyBeltStr = safetyBeltStr.substring(0, safetyBeltStr.length - 1);
			}
			
			if(bothHandsStr !=''){
				bothHandsStr = bothHandsStr.substring(0, bothHandsStr.length - 1);
			}
			if(fatigueStr !=''){
				fatigueStr = fatigueStr.substring(0, fatigueStr.length - 1);
			}
			
			if(otherRiskStr !=''){
				otherRiskStr = otherRiskStr.substring(0, otherRiskStr.length - 1);
			}
			if(communicationStr !=''){
				communicationStr = communicationStr.substring(0, communicationStr.length - 1);
			}
			
			
			

           
			
			var totalNum = wubaoNum+riskTrueNum+otherRisk
			
			riskTrueNum = riskTrueNum+otherRisk


			var riskStr ='当日处置省智能监管系统各类风险预警（'+totalNum+'）宗，经核实，设备误报（'+wubaoNum+'）宗；属实风险（'+riskTrueNum+'）宗。其中，属实的风险预警中，接打电话（'+answerPhone+'）宗；抽烟（'+smoking+'）宗；玩手机（'+playPhone+'）宗；超速（'+overspeed+'）宗；超时驾驶（'+overtime+'）宗；设备遮挡失效报警（'+equipmentObstruction+'）宗；未系安全带报警（'+safetyBelt+'）宗；双手脱把报警（'+bothHands+'）宗；生理疲劳报警（'+fatigue+'）宗，设备通讯失效报警（'+communication+'）宗，其他风险属实（'+otherRisk+'）宗。'
			var monitorStr = '当天，'
			
			if(answerPhoneStr !=''){
				
				monitorStr = monitorStr+'（'+answerPhoneStr+')接打手机报警属实，'
				console.log(monitorStr)
			}
			
			if(playPhoneStr !=''){
				monitorStr = monitorStr+'（'+playPhoneStr+')玩手机报警属实，'
				console.log(monitorStr)
			}
			if(smokingStr !=''){
				monitorStr = monitorStr+'（'+smokingStr+')抽烟报警属实，'
				console.log(monitorStr)
			}
			
			if(overspeedStr !=''){
				monitorStr = monitorStr+'（'+overspeedStr+')超速报警属实，'
				console.log(monitorStr)
			}
			if(overtimeStr !=''){
				monitorStr = monitorStr+'（'+overtimeStr+')超时报警属实，'
				console.log(monitorStr)
			}
			
			if(equipmentObstructionStr !=''){
				monitorStr = monitorStr+'（'+equipmentObstructionStr+')设备遮挡失效报警属实，'
				console.log(monitorStr)
			}
			if(safetyBeltStr !=''){
				monitorStr = monitorStr+'（'+safetyBeltStr+')未系安全带报警属实，'
				console.log(monitorStr)
			}
			
			if(bothHandsStr !=''){
				monitorStr = monitorStr+'（'+bothHandsStr+')双手脱把报警属实，'
				console.log(monitorStr)
			}
			
			if(fatigueStr !=''){
				monitorStr = monitorStr+'（'+fatigueStr+')生理疲劳报警风险属实，'
				console.log(monitorStr)
			}
			
			if(communicationStr !=''){
				monitorStr = monitorStr+'（'+communicationStr+')设备通讯失效报警风险属实，'
				console.log(monitorStr)
			}
			
			
			if(otherRiskStr !=''){
				monitorStr = monitorStr+'（'+otherRiskStr+')其他风险属实，'
				console.log(monitorStr)
			}
			
			console.log(monitorStr)
			
			monitorStr= monitorStr+'建议加强对驾驶员的安全教育，培养良好的安全文明驾驶习惯。'
			
			document.getElementById("inputinfo").value = ''
			
			document.getElementById("riskStr").value = riskStr
			
			if(riskTrueNum !=0 ||  otherRisk !=0){
				document.getElementById("monitorStr").value = monitorStr
			}
			


        }
		
		

	function copyText(flag) {

            var select = ''
            if (flag === 1) {
                select = document.getElementById('riskStr')
                var cp2 = document.getElementById("cp2"); //
                cp2.style.display = "none";
            }

            if (flag === 2) {
                select = strf = document.getElementById('monitorStr')
                var cp1 = document.getElementById("cp1"); //
                cp1.style.display = "none";

            }
            if (select.value === '') {
                return

            }


            select.select(); //选中textarea中的内容
            try {
                var successful = document.execCommand('copy'); //执行复制命令
                if (successful) {
                    console.log('成功复制！');
                    if (flag === 1) {
                        var cp1 = document.getElementById("cp1"); //
                        cp1.style.display = "block";
                    }

                    if (flag === 2) {
                        var cp2 = document.getElementById("cp2"); //
                        cp2.style.display = "block";
                    }

                } else {
                    console.log('无法复制！');
                }
            } catch (err) {
                console.error('无法复制！', err);
            }
        }




        document.onkeydown = function (e) {
            var ev = document.all ? window.event : e;
            if (ev.keyCode == 13) {
                var cp1 = document.getElementById("cp1"); //
                cp1.style.display = "none";

                var cp2 = document.getElementById("cp2"); //
                cp2.style.display = "none";
                risk()
            }
        }


        



    </script>

    <script src="../js/bootstrap.bundle.min.js"></script>
</body>

</html>